#include "MyFloat.h"

// Constructors/Destructors
//

MyFloat::MyFloat ( ) {
    set(0);
}

MyFloat::MyFloat (float newVal ) {
    set(newVal);
}

MyFloat::~MyFloat ( ) { }

//
// Methods
//
MyFloat& MyFloat::operator=(const MyFloat &rhs) {
//     Only do assignment if RHS is a different object from this.
    if (this != &rhs) {
      value = rhs.get();
    }
    return *this;
}

MyFloat& MyFloat::operator+=(const MyFloat &rhs) {
//     Only do assignment if RHS is a different object from this.
    if (this != &rhs) {
      value = value+rhs.value;
    }
    return *this;
}

MyFloat& MyFloat::operator-=(const MyFloat &rhs) {
//     Only do assignment if RHS is a different object from this.
    if (this != &rhs) {
      value = value-rhs.value;
    }
    return *this;
}

MyFloat& MyFloat::operator*=(const MyFloat &rhs) {
//     Only do assignment if RHS is a different object from this.
    if (this != &rhs) {
      value = value*rhs.value;
    }
    return *this;
}

MyFloat& MyFloat::operator/=(const MyFloat &rhs) {
//     Only do assignment if RHS is a different object from this.
    if (this != &rhs) {
      value = value/rhs.value;
    }
    return *this;
}

  // Add this instance's value to other, and return a new instance
  // with the result.
  const MyFloat MyFloat::operator+(const MyFloat &other) const {
    return MyFloat(*this) += other;
  }

  // Multiply this instance's value to other, and return a new instance
  // with the result.
  const MyFloat MyFloat::operator*(const MyFloat &other) const {
    return MyFloat(*this) *= other;
  }

  // Divide this instance's value to other, and return a new instance
  // with the result.
  const MyFloat MyFloat::operator/(const MyFloat &other) const {
    return MyFloat(*this) /= other;
  }

  // Substract this instance's value to other, and return a new instance
  // with the result.
  const MyFloat MyFloat::operator-(const MyFloat &other) const {
    return MyFloat(*this) -= other;
  }

  // Substract this instance's value to other, and return a new instance
  // with the result.
  const MyFloat operator-(const MyFloat &other) {
    MyFloat temp;
    temp.set(-other.get());
    return temp;
  }

    // Compare this instance's value to other, and return a new instance
  // with the result.
  const bool MyFloat::operator<(const MyFloat &other) const {
    return this->value < other.get();
  }

//
void MyFloat::set(float newVal){
    this->value = newVal;
}

float MyFloat::get() const{
    return this->value;
}

